const install = (Vue, vm) => {
	/**
	 * 是否登录
	 */
	const isLogin = () =>{
		
		//如果没有token 跳转到登录页面
		// const token = vm.vuex_token
		// console.log(token,11)
		// if (!token) {
		// 	//来自哪个页面
			//console.log(getCurrentPages(),'currentPage')
			const currentPage = getCurrentPages().pop()
			//console.log(currentPage.route,'currentPage')
			//获取页面路径  和请求参数
			const {options,route} = currentPage
			//获取参数的key
			const optionsKeys = Object.keys(options)
			let params = ''
			if(optionsKeys.length !== 0){
				params = optionsKeys.reduce((pre,current) => {
					//es6写法
					return `${pre}${current}=${options[current]}&`
					//常规写法
				    // return pre + current + '=' + options[current] + '&'
				}, '?').slice(0, -1)
			}
			//缓存当前页  用于登录或者注册之后的跳转
			uni.setStorageSync('back_url',route + params)
			
			// 	return false
			console.log(route,'route')
			console.log(uni.getStorageSync('url'),'url')
			vm.$u.toast('请登录')
			if (uni.getStorageSync('url') != route) {
				setTimeout(() => {
					vm.$u.route({
						//type: 'redirect',
						url: 'pages/login/login',
					})
				}, 1000)
				
			}
			uni.setStorageSync('url',route)
		// }
		//return true
	}
	
	// 更新用户信息  并更新vuex_user
	
	const getUserInfo = async() =>{
		const res = await vm.$u.api.getUserInfo()
		return res
	}
	
	//判断设备信息
	
	const isAndroid = () =>{
		try{
			const res = uni.getSystemInfoSync()
			// console.log(res.platform)
			if (res.platform === 'andorid') return true
			return false
		} catch (e){
			
		}
	}
	
	vm.$u.utils = {
		isLogin,getUserInfo
	}
}
export default{
	install
}